package servlet;

import util.Linksql;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ManagerSeatServlet extends HttpServlet {
    int one=0;
    int two=0;
    int three=0;
    String sqlone="update seat set usestatus=? where seatnum=?";
    String sqltwo="update readroom set usestatus=? where readroomnum=?";
    String sqlthree="update seminar set usestatus=? where seminarnum=?";
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Connection con= Linksql.getConnection();
        PreparedStatement pre;
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String seatid=request.getParameter("hdd");//普通座位编号
        String status=request.getParameter("select");//座位状态
        try {
            pre=con.prepareStatement(sqlone);
            pre.setString(1,status);
            pre.setString(2,seatid);
            one=pre.executeUpdate();
            pre=con.prepareStatement(sqltwo);
            pre.setString(1,status);
            pre.setString(2,seatid);
            three=pre.executeUpdate();
            pre=con.prepareStatement(sqlthree);
            pre.setString(1,status);
            pre.setString(2,seatid);
            three=pre.executeUpdate();
            if((one==0)&&(two==0)&&(three==0)){
                response.getWriter().write("数据不存在");
            }else {
                response.getWriter().write("状态修改成功");
            }
            pre.close();
            con.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    }
